Page({
  data: {
    TabCur: 0,
    scrollLeft: 0,
    tablist: [
      "推荐", "穿搭", "美食", "彩妆", "影视", "职场", "情感", "家居", "美女", "JK", "男高"
    ],
    msg1: '1',
    allNoramalData: [{
        id: 1000,
        cover: "/image/sucai/物理老师打篮球一百个只进了三个_1_蛤？_来自小红书网页版.jpg",
        title: "物理老师打篮球一百个只进了三个",
        tx: "/image/sucai/c9ac2f1c-230d-4c80-ba00-401f6c66d92d.png",
        name: "蛤?",
        num: 10000,
        tran_num:"",
        islike: 1,
        tag: ["推荐", "穿搭", "职场"]
      },
      {
        id: 1001,
        cover: "/image/sucai/山东自考成绩_1_非酋_来自小红书网页版.jpg",
        title: "山东自考成绩",
        tx: "/image/sucai/e17c178b-bbc7-48c8-8063-74bcdd7146e9.png",
        name: "非酋?",
        num: 56,
        tran_num:"",
        islike: 0,
        tag: ["推荐", "穿搭", "男高"]
      },
      {
        id: 1002,
        cover: "/image/sucai/后悔没有早点来南昌😭真的太好吃了！！！_1_黑框（live纯享版）_来自小红书网页版.jpg",
        title: "后悔没有早点来南昌😭真的太好吃了！！！",
        tx: "/image/sucai/95d71d59-5a5f-4d61-b918-6837735e2332.png",
        name: "黑框",
        num: 2886,
        tran_num:"",
        islike: 0,
        tag: ["推荐", "美食"]
      },
      {
        id: 1003,
        cover: "/image/sucai/不懂就问，这车能跑过小米su7 Ultra吗？_1_山野睛子_来自小红书网页版.jpg",
        title: "不懂就问，这车能跑过小米su7 Ultra吗？",
        tx: "/image/sucai/2b747730-ccba-4759-b9b0-f1de69fd15f4.png",
        name: "山野睛子",
        num: 4087,
        tran_num:"",
        islike: 1,
        tag: ["推荐", "跑车", "职场"]
      },
      {
        id: 1004,
        cover: "/image/sucai/穷鬼女大学生没踩雷的一套化妆品_1_月昭海_来自小红书网页版.jpg",
        title: "穷鬼女大学生没踩雷的一套化妆品",
        tx: "/image/sucai/96229f7b-ef00-4659-bbaf-d1ef86302bbb.png",
        name: "月昭海",
        num: 9884,
        tran_num:"",
        islike: 1,
        tag: ["推荐", "彩妆", "美女"]
      },
      {
        id: 1005,
        cover: "/image/sucai/推荐九部今年新出国产剧，你看了几部？_1_是张鱼小丸子🎬_来自小红书网页版.jpg",
        title: "推荐九部今年新出国产剧，你看了几部？",
        tx: "/image/sucai/cdd70760-7538-49bd-8899-1f67d64a144d.png",
        name: "是张鱼小丸子🎬",
        num: 657,
        tran_num:"",
        islike: 1,
        tag: ["推荐", "影视", "情感"]
      }
    ]
  },

  onLoad(e) {
    this.countNum()
  },
  onShow(e) {
    this.countNum()
    let tag = this.data.tablist[this.data.TabCur]
    console.log(tag)
    let list = this.data.allNoramalData
    let dataList = []
    for (let i = 0; i < list.length; i++) {
      if (list[i].tag.indexOf(tag) != -1) {
        dataList.push(list[i])
      }
    }
    console.log(dataList)
    this.setData({
      noramalData: dataList
    })
  },

  tabSelect(e) {
    this.setData({
      TabCur: e.currentTarget.dataset.id,
      scrollLeft: (e.currentTarget.dataset.id - 1) * 60
    })
    this.onShow()
  },
  toLike(e) {
    console.log(e)
    let id = e.currentTarget.dataset.id
    console.log(id)
    let list = this.data.noramalData
    list.forEach(element => {
      if (element.id == id) {
        if (element.islike == 1) {
          element.islike = 0
          element.num -= 1
        } else {
          element.islike = 1
          element.num += 1
        }
      }
      this.onShow()
    });
  },
  countNum(){
    let list = this.data.allNoramalData
    for (let i = 0; i < list.length; i++) {
      console.log(list[i].num)
      let num = list[i].num
      if (num >= 10000) {
        num = (num / 10000).toFixed(1) + "万"
        console.log(num)
      }
      list[i].tran_num = num
    }
    this.setData({
      allNoramalData: list
    })
  },
  toSearch(){
    let user=wx.getStorageSync('userInfo')
    if(user==''){
      wx.navigateTo({
        url: 'pages/login/login',
      })
    }else{
      wx.navigateTo({
        url: 'pages/search/search',
      })
    }
  }
})